package progress.exa27_6;

import java.util.PriorityQueue;
import java.util.Queue;

public class PriorityQueueStudy {

    public Integer a;

    public static void main(String[] args) {
        Queue<Integer> queue = addTest();
        System.out.println("队列大小："+queue.size());
        queue = pollTest(queue);
        System.out.println("取出元素后队列大小："+queue.size());
        noCompareToTest();
    }

    /**
     * 添加元素进入队列
     * @return
     */
    public static Queue<Integer> addTest(){
        long start = System.currentTimeMillis();
        Queue<Integer> queue = new PriorityQueue<>();
        for(int i=1000;i>0;i--){
            boolean sus = queue.offer(i);
            if(sus) System.out.println("入队成功！");
        }
        System.out.println("添加耗时："+ (System.currentTimeMillis()-start)+"ms");
        return queue;
    }

    public static Queue<Integer> pollTest(Queue<Integer> queue){
        System.out.println("取出10个元素");
        for(int i=0;i<10;i++){
            System.out.print(queue.poll());
        }
        System.out.println();
        return queue;
    }

    public static Queue<PriorityQueueStudy> noCompareToTest(){
        long start = System.currentTimeMillis();
        Queue<PriorityQueueStudy> queue = new PriorityQueue<>();
        for(int i=10;i>0;i--){
            boolean sus = queue.offer(new PriorityQueueStudy());
            if(sus) System.out.println("入队成功！");
        }
        System.out.println("添加耗时："+ (System.currentTimeMillis()-start)+"ms");
        return queue;
    }


}
